import sqlite3 from 'sqlite3'
import { open } from 'sqlite'

const db = await open({
	filename: './database.db',
	driver: sqlite3.Database
})

// 用户表
await db.exec(`CREATE TABLE IF NOT EXISTS users (
	user_id TEXT PRIMARY KEY NOT NULL,
	user_name TEXT NOT NULL
)`)

// 机器人表
await db.exec(`CREATE TABLE IF NOT EXISTS bots (
	bot_id TEXT PRIMARY KEY NOT NULL,
	bot_name TEXT NOT NULL,
	bot_type TEXT NOT NULL,
	platform TEXT NOT NULL
)`)

// 群组表
await db.exec(`CREATE TABLE IF NOT EXISTS groups (
	group_id TEXT PRIMARY KEY NOT NULL,
	group_name TEXT NOT NULL
)`)

await db.exec(`CREATE TABLE IF NOT EXISTS records (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	user_id TEXT NOT NULL,
	group_id TEXT,
	bot_id TEXT NOT NULL,
	plugin TEXT NOT NULL,
	app TEXT NOT NULL,
	time INTEGER NOT NULL
)`)

export default db
